const app = getApp()
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   * id:任务ID
   */
  data: {
    publicUrl: app.globalData.publicUrl,
    order_id: '',
    bpj_uid: '',
    title: '',
    name: '',
    cone:'',
    number:'',
    date: util.formatTime(new Date),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      number: options.number,
    })

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  formSubmit: function (e) {
    var that = this
    console.log(that.data.number);
    console.log(e.detail.value.content);
    
    var timestamp = Date.parse(new Date());
    var timestamps = timestamp / 1000;
    var formatTime = util.formatTime(new Date);
    var codeLength = 8;
    var code = '';
    var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    for (var i = 0; i < codeLength; i++) {
      var index = Math.floor(Math.random() * 10);
      code += random[index];
    }
    var cone = formatTime + code
    that.setData({
      cone: cone
    })
    console.log(that.data.cone);
    wx.request({
      url: that.data.publicUrl + 'user_tk_state',
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      data: {
        order_number:that.data.number,
        tk_content: e.detail.value.content,
        tk_number: that.data.cone
      },
      success: function (res) {
        console.log(res)
        if (res.data.message == 'OK') {
          wx.showToast({
            title: '提交成功，等待审核',
            icon: 'none',
          })
          wx.reLaunch({
            // url: '/pages/myrelease/myrelease?currentTab=2' +'&release=3',
            url:'/pages/person/person',
          })
        }else{

        }

      },
      fail: function (res) {
        console.log('加载失败')
      }
    })
  },
})